<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .small{
            width: 200px;
            height: 200px;
            float: left;
        }
        .small img{
            width: 200px;
            height: 200px;
        }
        .mask{
            position: absolute;
            left: 0;
            top: 0;
            width: 50px;
            height: 50px;
            background-color: yellow;
            opacity: 0.5;
            display: none;
        }
        .big{
            float: left;
            width: 400px;
            height: 400px;
            position: relative;
            overflow: hidden;
            display: none;
        }
        .big img{
            position: absolute;
            left: 0;
            top: 0;
        }

    </style>
</head>
<body>
    <div class="small">
        <img src="../images/shouji.jpg" alt="">
        <div class="mask"></div>
    </div>
    <div class="big">
        <img src="../images/shouji.jpg" alt="">
    </div>

    <script>
        var mask=document.querySelector('.mask')
        var small=document.querySelector('.small')
        var img=document.querySelector('.big>img')
        var big=document.querySelector('.big')
        small.onmouseover=function()
        {
            big.style.display='block'
            mask.style.display='block'
        }
        small.onmouseout=function()
        {
            big.style.display='none'
            mask.style.display='none'
        }

        small.onmousemove=function(e)
        {
            var e=e||window.event;
            var x=e.clientX-this.offsetLeft-25
            var y=e.clientY-this.offsetTop-25

            if(x<0) x=0
            if(x>small.offsetWidth-mask.offsetWidth) x=small.offsetWidth-mask.offsetWidth
            if(y<0) y=0
            if(y>small.offsetHeight-mask.offsetHeight) y=small.offsetHeight-mask.offsetHeight

            // if(x>100) x=100
            // if(y>100) y=100

            // if(x<0) x=0
            // if(y<0) y=0

            mask.style.left=x+'px'
            mask.style.top=y+'px'

            img.style.left=(x*-4)+'PX'
            img.style.top=(y*-4)+'px'
        }
    </script>
    
</body>
</html>